package cn.edu.apollo.test;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;

/**
 * @PackageName: cn.edu.apollo.test
 * @ClassName: GetApolloConfigAppointNamesPace
 * @Description:
 * @author: RZS
 * @date: 2021/7/16  11:46
 */
public class GetApolloConfigAppointNamesPace {
    public static void main(String[] args) throws InterruptedException {
        // appointNamesSpace();
        appointNamesSpace1();
    }


    /**
     * 指定读取NamesSpace下的配置
     *      ConfigService.getConfig("spring-rocketmq")
     */
    private static void appointNamesSpace() throws InterruptedException {
        // 获取配置对象
        Config appConfig = ConfigService.getConfig("spring-rocketmq");

        //获取配置信息, 测试热发布
        while (true){
            Thread.sleep(3000);
            //获取配置信息,第一个参数：配置的key，第二个参数：默认值
            String value1 = appConfig.getProperty("rocketmq.name‐server", "获取失败");
            System.out.println(value1);
            String value2 = appConfig.getProperty("rocketmq.producer.group", "获取失败");
            System.out.println(value2);
        }
    }

    /**
     * 指定读取更公共的NamesSpace下的配置
     *      ConfigService.getConfig("spring-rocketmq")
     */
    private static void appointNamesSpace1() throws InterruptedException {
        // 获取配置对象
        Config appConfig = ConfigService.getConfig("micro_service.spring-boot-http");

        //获取配置信息, 测试热发布
        while (true){
            Thread.sleep(3000);
            //获取配置信息,第一个参数：配置的key，第二个参数：默认值
            String value11 = appConfig.getProperty("rocketmq.name‐server", "获取失败");
            System.out.println(value11);
            String value22 = appConfig.getProperty("rocketmq.producer.group", "获取失败");
            System.out.println(value22);
            System.out.println("================================================");
            String value1 = appConfig.getProperty("spring.http.encoding.enabled", "获取失败");
            System.out.println(value1);
            String value2 = appConfig.getProperty("spring.http.encoding.charset", "获取失败");
            System.out.println(value2);
            String value3 = appConfig.getProperty("spring.http.encoding.force", "获取失败");
            System.out.println(value3);
            String value4 = appConfig.getProperty("server.tomcat.remote_ip_header", "获取失败");
            System.out.println(value4);
            String value5 = appConfig.getProperty("server.tomcat.protocol_header", "获取失败");
            System.out.println(value5);
            String value6 = appConfig.getProperty("server.use‐forward‐headers", "获取失败");
            System.out.println(value6);
            String value7 = appConfig.getProperty("server.servlet.context‐path", "获取失败");
            System.out.println(value7);
        }
    }
}
